

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="Description" content="scikit-learn: machine learning in Python">

  
  <title>scikit-learn: machine learning in Python &mdash; scikit-learn 0.22 documentation</title>
  
  <link rel="canonical" href="http://scikit-learn.org/stable/index.html" />

  
  <link rel="shortcut icon" href="_static/favicon.ico"/>
  

  <link rel="stylesheet" href="_static/css/vendor/bootstrap.min.css" type="text/css" />
  <link rel="stylesheet" href="_static/gallery.css" type="text/css" />
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script> 
</head>
<body>
<nav id="navbar" class="sk-landing-navbar navbar navbar-expand-md navbar-light bg-light py-0">
  <div class="container-fluid sk-landing-container px-0">
      <a class="navbar-brand py-0" href="#">
        <img
          class="sk-brand-img"
          src="_static/scikit-learn-logo-small.png"
          alt="logo"/>
      </a>
    <button
      id="sk-navbar-toggler"
      class="navbar-toggler"
      type="button"
      data-toggle="collapse"
      data-target="#navbarSupportedContent"
      aria-controls="navbarSupportedContent"
      aria-expanded="false"
      aria-label="Toggle navigation"
    >
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="sk-navbar-collapse collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="install.html">Install</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="user_guide.html">User Guide</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="modules/classes.html">API</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="auto_examples/index.html">Examples</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="getting_started.html">Getting Started</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="tutorial/index.html">Tutorial</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="glossary.html">Glossary</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="developers/index.html">Development</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="faq.html">FAQ</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="related_projects.html">Related packages</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="roadmap.html">Roadmap</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="about.html">About us</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://github.com/scikit-learn/scikit-learn">GitHub</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://scikit-learn.org/dev/versions.html">Other Versions</a>
        </li>
        <li class="nav-item dropdown nav-more-item-dropdown">
          <a class="sk-nav-link nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">More</a>
          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
              <a class="sk-nav-dropdown-item dropdown-item" href="getting_started.html">Getting Started</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="tutorial/index.html">Tutorial</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="glossary.html">Glossary</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="developers/index.html">Development</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="faq.html">FAQ</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="related_projects.html">Related packages</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="roadmap.html">Roadmap</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="about.html">About us</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="https://github.com/scikit-learn/scikit-learn">GitHub</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="https://scikit-learn.org/dev/versions.html">Other Versions</a>
          </div>
        </li>
      </ul>
      <div id="searchbox" role="search">
          <div class="searchformwrapper">
          <form class="search" action="search.html" method="get">
            <input class="sk-search-text-input" type="text" name="q" aria-labelledby="searchlabel" />
            <input class="sk-search-text-btn" type="submit" value="Go" />
          </form>
          </div>
      </div>
    </div>
  </div>
</nav>
<div class="container-fluid sk-landing-bg py-3">
  <div class="container sk-landing-container">
    <div class="row">
      <div class="col-md-6 mb-3 mb-md-0">
        <h1 class="sk-landing-header text-white text-monospace">scikit-learn</h1>
        <h4 class="sk-landing-subheader text-white font-italic mb-3">Machine Learning in Python</h4>
        <a class="btn sk-landing-btn mb-1" href="getting_started.html" role="button">Getting Started</a>
        <a class="btn sk-landing-btn mb-1" href="whats_new/v0.22.html" role="button">What's New in 0.22</a>
        <a class="btn sk-landing-btn mb-1" href="https://github.com/scikit-learn/scikit-learn" role="button">GitHub</a>
      </div>
      <div class="col-md-6 d-flex">
        <ul class="sk-landing-header-body">
          <li>Simple and efficient tools for predictive data analysis</li>
          <li>Accessible to everybody, and reusable in various contexts</li>
          <li>Built on NumPy, SciPy, and matplotlib</li>
          <li>Open source, commercially usable - BSD license</li>
        </ul>
      </div>
    </div>
  </div>
</div>

<div class="container sk-landing-container pt-3 body" role="main">
  <div class="row no-gutters">
    <div class="col-md-4 mb-3 px-md-2 sk-px-xl-4">
      <div class="card h-100">
        <div class="card-body">
          <a href="supervised_learning.html#supervised-learning"><h4 class="sk-card-title card-title">Classification</h4></a>
          <p class="card-text">Identifying which category an object belongs to.</p>
          <p class="card-text"><strong>Applications:</strong> Spam detection, image recognition.</br>
          <strong>Algorithms:</strong>
          <a href="modules/svm.html#svm-classification">SVM</a>,
          <a href="modules/neighbors.html#classification">nearest neighbors</a>,
          <a href="modules/ensemble.html#forest">random forest</a>,
          and <a href="supervised_learning.html#supervised-learning">more...</a></p>
        </div>
        <div class="overflow-hidden mx-2 text-center flex-fill">
          <a href="auto_examples/classification/plot_classifier_comparison.html"  aria-label="Classification">
          <img src="_images/sphx_glr_plot_classifier_comparison_001_carousel.png" class="sk-index-img" style="width:initial;max-width:initial" alt="Classifier comparison">
          </a>
        </div>
          <a href="auto_examples/index.html#classification" class="sk-btn-primary btn text-white btn-block" role="button">Examples</a>
      </div>
    </div>
    <div class="col-md-4 mb-3 px-md-2 sk-px-xl-4">
      <div class="card h-100">
        <div class="card-body">
          <a href="supervised_learning.html#supervised-learning"><h4 class="sk-card-title card-title">Regression</h4></a>
          <p class="card-text">Predicting a continuous-valued attribute associated with an object.</p>
          <p class="card-text"><strong>Applications:</strong> Drug response, Stock prices.</br>
          <strong>Algorithms:</strong>
          <a href="modules/svm.html#svm-regression">SVR</a>,
          <a href="modules/linear_model.html#ridge-regression">nearest neighbors</a>,
          <a href="modules/linear_model.html#lasso">random forest</a>,
          and <a href="supervised_learning.html#supervised-learning">more...</a></p>
        </div>
        <div class="overflow-hidden mx-2 text-center flex-fill">
          <a href="auto_examples/ensemble/plot_adaboost_regression.html"  aria-label="Regression">
          <img src="_images/sphx_glr_plot_adaboost_regression_thumb.png" class="sk-index-img" alt="Decision Tree Regression with AdaBoost">
          </a>
        </div>
          <a href="auto_examples/index.html#examples" class="sk-btn-primary btn text-white btn-block" role="button">Examples</a>
      </div>
    </div>
    <div class="col-md-4 mb-3 px-md-2 sk-px-xl-4">
      <div class="card h-100">
        <div class="card-body">
          <a href="modules/clustering.html#clustering"><h4 class="sk-card-title card-title">Clustering</h4></a>
          <p class="card-text">Automatic grouping of similar objects into sets.</p>
          <p class="card-text"><strong>Applications:</strong> Customer segmentation, Grouping experiment outcomes</br>
          <strong>Algorithms:</strong>
          <a href="modules/clustering.html#k-means">k-Means</a>,
          <a href="modules/clustering.html#spectral-clustering">spectral clustering</a>,
          <a href="modules/clustering.html#mean-shift">mean-shift</a>,
          and <a href="modules/clustering.html#clustering">more...</a></p>
        </div>
        <div class="overflow-hidden mx-2 text-center flex-fill">
          <a href="auto_examples/cluster/plot_kmeans_digits.html"  aria-label="Clustering">
          <img src="_images/sphx_glr_plot_kmeans_digits_thumb.png" class="sk-index-img" alt="A demo of K-Means clustering on the handwritten digits data">
          </a>
        </div>
          <a href="auto_examples/index.html#cluster-examples" class="sk-btn-primary btn text-white btn-block" role="button">Examples</a>
      </div>
    </div>
    <div class="col-md-4 mb-3 px-md-2 sk-px-xl-4">
      <div class="card h-100">
        <div class="card-body">
          <a href="modules/decomposition.html#decompositions"><h4 class="sk-card-title card-title">Dimensionality reduction</h4></a>
          <p class="card-text">Reducing the number of random variables to consider.</p>
          <p class="card-text"><strong>Applications:</strong> Visualization, Increased efficiency</br>
          <strong>Algorithms:</strong>
          <a href="modules/decomposition.html#pca">k-Means</a>,
          <a href="modules/feature_selection.html#feature-selection">feature selection</a>,
          <a href="modules/decomposition.html#nmf">non-negative matrix factorization</a>,
          and <a href="modules/decomposition.html#decompositions">more...</a></p>
        </div>
        <div class="overflow-hidden mx-2 text-center flex-fill">
          <a href="auto_examples/decomposition/plot_pca_iris.html"  aria-label="Dimensionality reduction">
          <img src="_images/sphx_glr_plot_pca_iris_thumb.png" class="sk-index-img" alt="PCA example with Iris Data-set">
          </a>
        </div>
          <a href="auto_examples/index.html#decomposition-examples" class="sk-btn-primary btn text-white btn-block" role="button">Examples</a>
      </div>
    </div>
    <div class="col-md-4 mb-3 px-md-2 sk-px-xl-4">
      <div class="card h-100">
        <div class="card-body">
          <a href="model_selection.html#model-selection"><h4 class="sk-card-title card-title">Model selection</h4></a>
          <p class="card-text">Comparing, validating and choosing parameters and models.</p>
          <p class="card-text"><strong>Applications:</strong> Improved accuracy via parameter tuning</br>
          <strong>Algorithms:</strong>
          <a href="modules/grid_search.html#grid-search">grid search</a>,
          <a href="modules/cross_validation.html#cross-validation">cross validation</a>,
          <a href="modules/model_evaluation.html#model-evaluation">metrics</a>,
          and <a href="modules/decomposition.html#decompositions">more...</a></p>
        </div>
        <div class="overflow-hidden mx-2 text-center flex-fill">
          <a href="auto_examples/model_selection/plot_multi_metric_evaluation.html"  aria-label="Model selection">
            <img src="_images/sphx_glr_plot_multi_metric_evaluation_thumb.png" class="sk-index-img" alt="Demonstration of multi-metric evaluation on cross_val_score and GridSearchCV">
          </a>
        </div>
          <a href="auto_examples/index.html#model-selection" class="sk-btn-primary btn text-white btn-block" role="button">Examples</a>
      </div>
    </div>
    <div class="col-md-4 mb-3 px-md-2 sk-px-xl-4">
      <div class="card h-100">
        <div class="card-body">
          <a href="modules/preprocessing.html#preprocessing"><h4 class="sk-card-title card-title">Preprocessing</h4></a>
          <p class="card-text">Feature extraction and normalization.</p>
          <p class="card-text"><strong>Applications:</strong>  Transforming input data such as text for use with machine learning algorithms.</br>
          <strong>Algorithms:</strong>
          <a href="modules/preprocessing.html#preprocessing">preprocessing</a>,
          <a href="modules/feature_extraction.html#feature-extraction">feature extraction</a>,
          and <a href="modules/preprocessing.html#preprocessing">more...</a></p>
        </div>
        <div class="overflow-hidden mx-2 text-center flex-fill">
          <a href="auto_examples/preprocessing/plot_discretization_strategies.html"  aria-label="Preprocessing">
          <img src="_images/sphx_glr_plot_discretization_strategies_thumb.png" class="sk-index-img" alt="Demonstrating the different strategies of KBinsDiscretizer">
          </a>
        </div>
          <a href="auto_examples/index.html#preprocessing" class="sk-btn-primary btn text-white btn-block" role="button">Examples</a>
      </div>
    </div>
  </div>
</div>

<div class="container-fluid sk-landing-bg-more-info py-3">
  <div class="container sk-landing-container">
    <div class="row">
      <div class="col-md-4">
        <h4 class="sk-landing-call-header">News</h4>
        <ul class="sk-landing-call-list list-unstyled">
        <li><strong>On-going development:</strong>
        <a href="https://scikit-learn.org/dev/whats_new.html"><strong>What's new</strong> (Changelog)</a>
        </li>
        <li><strong>December 2019.</strong> scikit-learn 0.22 is available for download (<a href="whats_new/v0.22.html#version-0-22-0">Changelog</a>).
        </li>
        <li><strong>Scikit-learn from 0.21 requires Python 3.5 or greater.</strong>
        </li>
        <li><strong>July 2019.</strong> scikit-learn 0.21.3 (<a href="whats_new/v0.21.html#version-0-21-3">Changelog</a>) and 0.20.4 (<a href="whats_new/v0.20.html#version-0-20-4">Changelog</a>) are available for download.
        </li>
        <li><strong>May 2019.</strong> scikit-learn 0.21.0 to 0.21.2 are available for download (<a href="whats_new/v0.21.html#version-0-21-2">Changelog</a>).
        </li>
        <li><strong>March 2019.</strong> scikit-learn 0.20.3 is available for download (<a href="whats_new/v0.20.html#version-0-20-3">Changelog</a>).
        </li>
        <li><strong>September 2018.</strong> scikit-learn 0.20.0 is available for download (<a href="whats_new/v0.20.html#version-0-20-0">Changelog</a>).
        </li>
        <li><strong>July 2018.</strong> scikit-learn 0.19.2 is available for download (<a href="whats_new/v0.19.html#version-0-19-2">Changelog</a>).
        </li>
        <li><strong>July 2017.</strong> scikit-learn 0.19.0 is available for download (<a href="whats_new/v0.19.html#version-0-19">Changelog</a>).
        </li>
        </ul>
      </div>
      <div class="col-md-4">
        <h4 class="sk-landing-call-header">Community</h4>
        <ul class="sk-landing-call-list list-unstyled">
        <li><strong>About us:</strong> See <a href="about.html#people">authors</a> and <a href="developers/contributing.html">contributing</a></li>
        <li><strong>More Machine Learning:</strong> Find <a href="related_projects.html">related projects</a></li>
        <li><strong>Questions?</strong> See <a href="faq.html">FAQ</a> and <a href="https://stackoverflow.com/questions/tagged/scikit-learn">stackoverflow</a></li>
        <li><strong>Mailing list:</strong> <a href="https://mail.python.org/mailman/listinfo/scikit-learn">scikit-learn@python.org</a></li>
        <li><strong>Gitter:</strong> <a href="https://gitter.im/scikit-learn/scikit-learn">gitter.im/scikit-learn</a></li>
        </ul>

        <form target="_top" id="paypal-form" method="post" action="https://www.paypal.com/cgi-bin/webscr">
          <input type="hidden" value="_s-xclick" name="cmd">
          <input type="hidden" value="74EYUMF3FTSW8" name="hosted_button_id">
        </form>
        <a class="btn btn-warning btn-big sk-donate-btn mb-1" onclick="document.getElementById('paypal-form').submit(); ">Help us, <strong>donate!</strong></a>
        <a class="btn btn-warning btn-big mb-1" href="about.html#citing-scikit-learn"><strong>Cite us!</strong></a>
      </div>
      <div class="col-md-4">
        <h4 class="sk-landing-call-header">Who uses scikit-learn?</h4>
        <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner">
            <div class="carousel-item active">
            <img class="d-block mx-auto sk-who-uses-carousel-img img-thumbnail" src="_images/inria.png" alt="inria">
            <em>"We use scikit-learn to support leading-edge basic research [...]"</em>
            </div>
            <div class="carousel-item">
            <img class="d-block mx-auto sk-who-uses-carousel-img img-thumbnail" src="_images/spotify.png" alt="spotify">
            <em>"I think it's the most well-designed ML package I've seen so far."</em>
            </div>
            <div class="carousel-item">
            <img class="d-block mx-auto sk-who-uses-carousel-img img-thumbnail" src="_images/change-logo.png" alt="change-logo">
            <em>"scikit-learn's ease-of-use, performance and overall variety of algorithms implemented has proved invaluable [...]."</em>
            </div>
            <div class="carousel-item">
            <img class="d-block mx-auto sk-who-uses-carousel-img img-thumbnail" src="_images/telecomparistech.jpg" alt="telecomparistech">
            <em>"The great benefit of scikit-learn is its fast learning curve [...]"</em>
            </div>
            <div class="carousel-item">
            <img class="d-block mx-auto sk-who-uses-carousel-img img-thumbnail" src="_images/aweber.png" alt="aweber">
            <em>"It allows us to do AWesome stuff we would not otherwise accomplish"</em>
            </div>
            <div class="carousel-item">
            <img class="d-block mx-auto sk-who-uses-carousel-img img-thumbnail" src="_images/yhat.png" alt="yhat">
            <em>"scikit-learn makes doing advanced analysis in Python accessible to anyone."</em>
            </div>
          </div>
        </div>
        <p class="text-right">
            <a href="testimonials/testimonials.html">More testimonials</a>
        </p>
      </div>
    </div>
  </div>
</div>
<div class="container-fluid py-3">
  <div class="container sk-landing-container">
        <a class="sk-footer-funding-link" href="about.html#funding">
        <div class="text-center">
                <p class="mt-2">
                  scikit-learn development and maintenance are financially supported by
                </p>
                <img class="sk-footer-funding-logo" src="_static/inria-small.png" title="INRIA">
                <img class="sk-footer-funding-logo" src="_static/columbia-small.png" title="Columbia University">
                <img class="sk-footer-funding-logo" src="_static/sloan_logo-small.png" title="Alfred P. Sloan Foundation" >
                <img class="sk-footer-funding-logo" src="_static/sydney-stacked-small.png" title="The University of Sydney">
                <img class="sk-footer-funding-logo" src="_static/microsoft-small.png" title="Microsoft" >
                <img class="sk-footer-funding-logo" src="_static/bcg-small.png" title="Boston Consulting Group" >
                <img class="sk-footer-funding-logo" src="_static/axa-small.png" title="AXA Assurances" >
                <img class="sk-footer-funding-logo" src="_static/bnp-small.png" title="BNP Paris Bas Cardif" >
                <img class="sk-footer-funding-logo" src="_static/fujitsu-small.png" title="Fujitsu" >
                <img class="sk-footer-funding-logo" src="_static/intel-small.png" title="Intel" >
                <img class="sk-footer-funding-logo" src="_static/nvidia-small.png" title="Nvidia" >
                <img class="sk-footer-funding-logo" src="_static/dataiku-small.png" title="Dataiku" >
                <img class="sk-footer-funding-logo" src="_static/anaconda-small.png" title="Anaconda" >
        </div>
        </a>
  </div>
</div>

<script src="_static/js/vendor/bootstrap.min.js"></script>

<script>
    window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
    ga('create', 'UA-22606712-2', 'auto');
    ga('set', 'anonymizeIp', true);
    ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>


<script>
$(document).ready(function() {
    /* Add a [>>>] button on the top-right corner of code samples to hide
     * the >>> and ... prompts and the output and thus make the code
     * copyable. */
    var div = $('.highlight-python .highlight,' +
                '.highlight-python3 .highlight,' +
                '.highlight-pycon .highlight,' +
		'.highlight-default .highlight')
    var pre = div.find('pre');

    // get the styles from the current theme
    pre.parent().parent().css('position', 'relative');
    var hide_text = 'Hide prompts and outputs';
    var show_text = 'Show prompts and outputs';

    // create and add the button to all the code blocks that contain >>>
    div.each(function(index) {
        var jthis = $(this);
        if (jthis.find('.gp').length > 0) {
            var button = $('<span class="copybutton">&gt;&gt;&gt;</span>');
            button.attr('title', hide_text);
            button.data('hidden', 'false');
            jthis.prepend(button);
        }
        // tracebacks (.gt) contain bare text elements that need to be
        // wrapped in a span to work with .nextUntil() (see later)
        jthis.find('pre:has(.gt)').contents().filter(function() {
            return ((this.nodeType == 3) && (this.data.trim().length > 0));
        }).wrap('<span>');
    });

    // define the behavior of the button when it's clicked
    $('.copybutton').click(function(e){
        e.preventDefault();
        var button = $(this);
        if (button.data('hidden') === 'false') {
            // hide the code output
            button.parent().find('.go, .gp, .gt').hide();
            button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden');
            button.css('text-decoration', 'line-through');
            button.attr('title', show_text);
            button.data('hidden', 'true');
        } else {
            // show the code output
            button.parent().find('.go, .gp, .gt').show();
            button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible');
            button.css('text-decoration', 'none');
            button.attr('title', hide_text);
            button.data('hidden', 'false');
        }
    });

	/*** Add permalink buttons next to glossary terms ***/
	$('dl.glossary > dt[id]').append(function() {
		return ('<a class="headerlink" href="#' +
			    this.getAttribute('id') +
			    '" title="Permalink to this term">¶</a>');
	});
});

</script>
</body>
</html>